package org.netwia.networks.nodes;

import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.netwia.networks.Node;

/**
 * Implementation of node which prints inputs to the standard output stream and returns null.
 * 
 * @author radek.hecl
 *
 * @param <T> type of the network parameter
 */
public class StandardOutputNode<T> implements Node<T> {

    /**
     * Builder object.
     * 
     * @param <T> type of the network parameter
     */
    public static class Builder<T> {

        /**
         * Builds the result object.
         * 
         * @return created object
         */
        public StandardOutputNode<T> build() {
            return new StandardOutputNode<T>(this);
        }
    }

    /**
     * Creates new instance.
     * 
     * @param builder builder object
     */
    public StandardOutputNode(Builder<T> builder) {
        guardInvariants();
    }

    /**
     * Guards this object to be consistent. Throws exception if this is not the case.
     */
    private void guardInvariants() {
    }

    @Override
    public T process(Map<String, T> inputs) {
        System.out.println(inputs);
        return null;
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

}
